package demo08;

import java.lang.reflect.Method;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/10/27 17:16
 */
public class Test {
    public static void main(String[] args) throws Exception{
        Class aClass = Class.forName("demo08.Mouse");

        Method use = aClass.getDeclaredMethod("use");
        use.setAccessible(true);

        Object o = aClass.newInstance();
        Object result = use.invoke(o);
        System.out.println(result);

        Method use3 = aClass.getMethod("use3", Integer.class);
        Object result2 = use3.invoke(o, 100);
        System.out.println(result2);


    }
}
class Computer{
    public int age;
    private String kind;
    public String use3(Integer a){
        System.out.println("这是父类的use3方法");
        return "aaa";
    }
}

class Mouse extends Computer {
    private double price;
    public int size;

    public void use(){
        System.out.println("这是use方法");
    }
    private void use2(Integer a){
        System.out.println("这是use2方法");
    }

    @Override
    public String toString() {
        return "Mouse{" +
                "age=" + age +
                ", price=" + price +
                ", size=" + size +
                '}';
    }
}